package com.gyh.system.gen.utils;

import java.io.FileNotFoundException;
import java.io.PrintWriter;

import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;


/**
* @author 作者 gyh:
* @version 创建时间：2018年1月19日 上午11:40:06
* 
*/
public class MakerUtils {

	public static void inParameters() {
		 
		 Template t = Velocity.getTemplate("");
		 VelocityContext ctx = new VelocityContext();
		
	}

	public static void merge(Template template, VelocityContext ctx, String path) {
		 PrintWriter writer = null;
		 try {
			 writer = new PrintWriter(path);
			 template.merge(ctx, writer);
			 writer.flush();
		 } catch (FileNotFoundException e) {
			 e.printStackTrace();
		 } finally {
			 writer.close();
		 }
	}
	
	
//	public static <T> T fileToObject() {
//	try {
//		String pathName = "/data.xml";
//		Resource resource = new ClassPathResource(pathName);
//		InputStream is = resource.getInputStream();
//	    // 构建FileInputStream对象
//	    
//	    InputStreamReader reader = new InputStreamReader(is, "UTF-8");
//	    // 构建InputStreamReader对象,编码与写入相同
//	    BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
//	    StringBuffer sb = new StringBuffer();
//	    while (true) {
//			String line = br.readLine();
//			if (line == null){
//				break;
//			}
//			sb.append(line).append("\r\n");
//		}
//	    FileUtils.write(new File("E:/a.java"), sb.toString(), "utf-8");
//	    Template temp = new Template("name",new StringReader(sb.toString()), new Configuration());
//	    StringWriter result = new StringWriter();
//	    Map<String,String> map = new HashMap<>();
//	    map.put("ClassName", "这是被替换的数据");
//	    temp.process(map, result);
//	    System.out.println(result.toString());
//	}catch (Exception e) {
//		// TODO: handle exception
//	}
//	return null;
//}
}
